

public abstract class Controllable extends Tileable {
	
	//Variables
	protected boolean canAttack;		// tell if a Controllable is allowed to attack
	protected char label;
	protected int armor;
	protected int damage;		//	DAMAGE :
					// Also, I plan on a way to deal damage. There will be a variable, damage will accumulate during the tick and will modify the damage counter. When endTick() is all, the total amount of damager will be subtracted from health (healing taken into account) and the endTick() will figure out if the controllable has died or not. At the end of endTick(), it will reset the damage counter.
					
	protected int maxHealth, health;
	protected int originalOffence, originalDefence;
	protected int offence, defence;

			//allocations
	protected int energy, energyRT,energyORT; //NOTE: energy is current allocated energy. energyRT is the rate it current consumes energy
	protected int nutrient, nutrientRT, nutrientORT;	// and energyORT is the original rate of consumption
	protected int metal, metalRT, metalORT;
	
	protected String mode;
	static Map map;
	

	public Controllable(int _x,int _y){
		super(_x, _y);
		canAttack = false;
		map.addTileable(x,y,this);
	}
	//=========  GETTERS ============
	public int getHealth(){return health;}
	int getArmor(){return armor;}
	int getEnergy(){return energy;}
	int getMetal(){return metal;}
	int getNutrient(){return nutrient;}
	int getEnergyRT(){return energyRT;}
	int getMetalRT(){return metalRT;}
	int getNutrientRT(){return nutrientRT;}
	int defence(){return defence;}	
	public char getLabel(){return label;}
	
	
	public String getTypeName() {
		switch (type) {
		case 1:	return "Farm";
		case 2:	return "Mine";
		case 3:	return "Power Plant";
		case 4: return "Fort";
		case 5:	return "Base";
		case 6:	return "Tower";
		case 11:return "Melee";
		case 32:return "Ranged";
		case 13: return "Explorer";
		case 14: return "Colonist";
		case 15: return "Rally";
		default:return "Unknown";
		}
	}
	
	//======SETTERS===========
	void modOffence(int mod){offence = mod;}	//will change the value of modOffence absolutely. (offence = int)
		
	//will change the value of modOffence by a percentage based on offence. offence = offence * float)
	void modOffence(float mod){ offence = (int)(mod * originalOffence);} 
	void modOffence(){	offence = originalOffence;}	//will change the value of offence back to originalOffence
	
	void modDefence(int mod){defence = mod;}
	void modDefence(float mod){defence = (int)(mod * originalDefence);}
	void modDefence(){defence = originalDefence;}
	
	boolean damage(){return damage(10);}
	boolean damage(float x){return damage((int)(health*x)+1);	}
	
	boolean damage(int x){ 
		if(x == 0)
			return true;
		if(x <5)
			x = 5;
		
		if(health - x > 0){
			health -= x; 
			return true;
		}
		else{
			health = 0; 
			return false;
		}
	}	
	
	public void powerDown(){ 
		energyRT = (int)(energyORT *.25);
		nutrientRT = (int)(nutrientORT *.25);
		metalRT = (int)(metalORT *.25);
	}
	
	public void powerUp(){ 
		energyRT = energyORT ;
		nutrientRT = nutrientORT;
		metalRT = metalORT;
	}
	// ============= DO STUFF =================
	
	static void addMap(Map _map){map = _map;}
	public void visible(int type){map.visible(x,y,type);}
	
	void allocate(int _nutrient){nutrient += _nutrient;	}
	void allocate(int _nutrient, int _metal){
		nutrient+=nutrient;
		metal+= _metal;
	}
	
	void allocate(int _nutrient, int _metal,int _energy){	//the three will allocate food, metal and power to the Controllables
		nutrient+=nutrient;
		metal+= _metal;
		energy += _energy;
	}
	
	abstract int endTick();	//This should be called at the end of every tick. It will decrement the amount of resources based on the rate, and take care of whatever else that needs to be done for. WIll return a -1, 0, or 1. 
							// -1 = the item has died due to lack of resources or whatever else
							// 0 = the item has a lack of resources and is dying
							// 1 = everything is fine.
												
	
	
	//================COMMAND QUEUE ======================
	
	//		task
	final int DAMAGE = 1, POWERUP = 2, POWERDOWN = 3, DIE = 4;
	
	protected RTSQueue<int[]> commandQueue = new RTSQueue<int[]>();
	
	
	public void addCommand(int[] command) {commandQueue.addLast(command);}
	public void cancelCommand(){commandQueue.pop();}
	public void delCommands() {commandQueue.clear();}
	
	public void nextCommand(){
		
		if(!commandQueue.isEmpty()){
			int[] x = commandQueue.pop();
			
			if(x[0] <= 1){
				interpret(x);
				return;
			}
			x[0]--;
			commandQueue.addFirst(x);
		}
	}
	
	public void interpret(int[] task){
		switch(task[1]){
			case DAMAGE : System.out.println("DAMAGE"); damage(task[2]);
			case POWERUP : System.out.println("POWERUP"); powerUp();
			case POWERDOWN : System.out.println("POWERDOWN"); powerDown();
			case DIE : System.out.println("DIE!"); die();
		}
	}
								
}
	
	
	
	
	
	
	
	
	
	